﻿using EntityPet;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PET.Tools;

namespace PET.Controllers
{
    /// <summary>
    /// 宠物保险方式控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class InsMethodController : ControllerBase
    {
        private readonly PetDbContext petM;
        public InsMethodController(PetDbContext db)
        {
            petM = db;
        }

        [HttpGet("ins")]
       public List<Pet_InsMethod> Getins()
        {
            return petM.Pet_InsMethod.ToList();
        }

        [HttpDelete("Del")]
        public bool Get(Guid id)
        {
           Pet_InsMethod? insm= petM.Pet_InsMethod.Where(m => m.InsMId == id).SingleOrDefault();
            if (insm!=null)
                petM.Pet_InsMethod.Remove(insm);
                int result = petM.SaveChanges();
                return result > 0;
            
        }

        [HttpGet("id")]
        public Result GetId(Guid id)
        {
            Result result = new Result();
            result.Data = petM.Pet_InsMethod.Where(w => w.InsMId == id).SingleOrDefault();
            return result;
        }

        [HttpPost]
        public Result AddPet([FromBody] Pet_InsMethod cover)
        {
            Result result = new Result();
            petM.Pet_InsMethod.Add(cover);
            result.Data = petM.SaveChanges();
            return result;
        }

        [HttpPut]
        public Result Put([FromBody] Pet_InsMethod cover)
        {
            Result result = new Result();
            petM.Pet_InsMethod.Update(cover);
            result.Data = petM.SaveChanges();
            return result;
        }
    }
}
